var postsId = getQuery('id')
console.log(postsId)
window.onload = function(){
    initposts()
}

function initposts(){
    axios.get("/posts/selectPosts",{
        params:{
            postsId:postsId
        }
    }).then(resp =>{
        $('top').innerHTML ="主题:"+ resp.data.theme
        // console.log(resp.data.writer.imgPath);
        let aboutStr = `
 
<div class="user-info" style="float: left;margin-right: 40px;">

    <div class="user-name">
       楼主: ${resp.data.writer.userName}
    </div>

    <div class="user-avatar">
    <img src="/img/${resp.data.writer.imgPath}" alt="用户头像">
    </div>

    <div class="user-date">
        注册日期：${resp.data.writer.regDate}
    </div>
</div>


<div class="post-info">
    <div class="post-title">
       主题: ${resp.data.theme}
    </div>
    <div class="post-content">
       内容: ${resp.data.content}
    </div>
</div>
</div>
        `
        $('about').innerHTML = aboutStr
        let info = resp.data
        let replayStr = ""
        info.replays.forEach(n => {
            replayStr += `
<div style="height:100px">
<div class="user-info" style="float: left;margin-right: 40px;">

<div class="user-name">
   楼主: ${n.replayor.userName}
</div>

<div class="user-avatar">
<img src="/img/${n.replayor.imgPath}" alt="用户头像">
</div>

<div class="user-date">
    注册日期：${n.replayor.regDate}
</div>
</div>

<div class="post-info">
<div class="post-title">
   标题: ${n.title}
</div>
<div class="post-content">
   内容: ${n.content}
</div>

</div>

</div>
<hr>
</div>
            `
        });
        $('replay').innerHTML = replayStr
        
    })
    
}

function submitReplay() {
    console.log(postsId)
    axios.get("/replay/addReplay",{
        params:{
            title:$('titleInput').value,
            content:$('contentInput').value,
            postsId:postsId
        }
    }).then(resp =>{
        console.log(resp.data)
        if (resp.data == "ok") {
            initposts()
        }
    })
}

function reset() {
    $('titleInput').value = ''
    $('contentInput').value = ''
}